package com.example.onlinejudge.controller;

import com.example.onlinejudge.mapper.ProblemMapper;
import com.example.onlinejudge.model.Answer;
import com.example.onlinejudge.model.Question;
import com.example.onlinejudge.service.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import java.io.IOException;

@Controller
public class TaskController {
    @Autowired
    private TaskService taskService;
    @Autowired
    private ProblemMapper problemMapper;

    public Answer compileAndRun(Question question) throws IOException, InterruptedException {
        if(!taskService.checkCodeSafe(question.getCode())){
            Answer answer=new Answer();
            System.out.println("用户提交了不安全的代码!");
            answer.setError(3);
            answer.setReason("您提交的代码可能会危害到服务器, 禁止运行!");
            return answer;
        }else{
            return taskService.compileAndRun(question);
        }
    }
}
